package com.mediastory.spsserver.customer.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.mediastory.spsserver.customer.dao.CustomerDao;
import com.mediastory.spsserver.customer.domain.Customer;
import com.mediastory.spsserver.customer.service.CustomerSvc;

/**
 * @author Jaewon Choi
 *
 */

@Service
@Transactional
public class CustomerSvcImpl implements CustomerSvc {

	@Autowired
	CustomerDao customerDao;
	
	public CustomerSvcImpl() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public List<Customer> findbyList(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		return (List<Customer>) (customerDao.SelectList(condition));
	}

	public Map<String, Object> findbyListPaging(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("customerList", (List<Customer>) (customerDao.SelectList(condition)));
		resultMap.put("customerListTotalCnt", (Integer) (customerDao.SelectListTotalCnt(condition)));
		
		return resultMap;
	}

	@Override
	public Customer findby(Integer idx) throws Exception {
		// TODO Auto-generated method stub
		return customerDao.select(idx);
	}

	@Override
	public Customer add(Customer customer) throws Exception {
		// TODO Auto-generated method stub
		Customer result = customerDao.insert(customer);
		
		return result;
	}

	@Override
	public Customer modify(Customer customer) throws Exception {
		// TODO Auto-generated method stub
		return customerDao.update(customer);
	}

	@Override
	public int remove(Map<String, Object> condition) throws Exception {
		// TODO Auto-generated method stub
		return customerDao.delete(condition);
	}

	@Override
	public String findbyChkDupl(Map<String, Object> condition) throws Exception {
		// TODO Auto-generated method stub
		
		String result = "true";
		Integer cnt = (Integer) (customerDao.SelectListTotalCnt(condition));
		if(cnt != null && cnt == 0){
			result = "false";
		}
		
		return result;
	}

}